package top.moonkit.rs_pro.patterns.login;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.moonkit.rs_pro.entity.User;
import top.moonkit.rs_pro.entity.vo.LoginRequestVO;
import top.moonkit.rs_pro.exception.BusinessException;
import top.moonkit.rs_pro.service.LoginCheckCodeService;
import top.moonkit.rs_pro.utils.Mu;

/**
 * @author moon
 * @since 0.0.1
 */
@Service
public class EMailCheckCodeLoginProcessor implements LoginProcessorService{

    @Autowired
    private LoginCheckCodeService loginCheckCodeService;

    @Override
    public boolean isMe(String account, Boolean isPassword) {
        return ((isPassword == null || !isPassword) && account.contains("@"));
    }

    @Override
    public void verifyAccount(LoginRequestVO vo, User user) {
        // 使用验证码登录
        if (!loginCheckCodeService.validateCode(vo.getAccount(), vo.getCode())){
            throw new BusinessException(Mu.m("login.code_error"));
        }
    }

}
